package com.sky.utils;



import com.sky.exception.CaptchaImageException;
import com.sky.exception.ServiceException;
import lombok.extern.slf4j.Slf4j;

/**
 * 抛异常工具类
 *
 * @author 菜篮
 */
@Slf4j
public class ThrowUtil {
    /**
     * 条件成立则抛异常
     *
     * @param condition
     */
    public static void throwIf(boolean condition, String msg) {
        if (condition) {
            throw new ServiceException(msg+"请联系教务系统开发组！");
        }
    }

    /**
     *抛异常
     *
     */
    public static void throwServiceExp(String msg) {
        log.error(msg);
        throw new ServiceException(msg);
    }
    /**
     * 抛异常
     *
     */
    public static void throwServiceExp(String msg,int code) {
        log.error(msg);
        throw new ServiceException(msg,code);
    }
    /**
     * 抛异常
     *
     */
    public static void throwServiceExp(int code) {
        throw new ServiceException("操作失败",code);
    }

    public static void throwIf(boolean condition, int code) {
        if (condition) {
            throw new ServiceException("操作失败", code);
        }
    }

    public static void throwIf(boolean condition, String msg, int code) {
        if (condition) {
            throw new ServiceException(msg, code);
        }
    }
}
